package com.rightrule.rule.compile;

import com.googlecode.aviator.Expression;
import com.rightrule.rule.constans.ScriptTypeEnum;
import lombok.Data;

import java.util.Map;

@Data
public class AviatorCompiledInstance implements CompilableInstance<Expression> {

    private final Expression expression;

    public AviatorCompiledInstance(Expression expression) {
        this.expression = expression;
    }

    @Override
    public ScriptTypeEnum getScriptType() {
        return ScriptTypeEnum.Aviator;
    }

    /**
     * 执行脚本
     *
     * @param variableMap
     * @return
     */
    @Override
    public Object execute(Map<String, Object> variableMap) {
        return expression.execute(variableMap);
    }

    @Override
    public Expression getCompiledInstance() {
        return getExpression();
    }
}
